package com.yunnuo.monitor.job.controller;

import com.yunnuo.monitor.job.entity.MonJobLog;
import com.yunnuo.monitor.job.service.IJobLogService;
import com.yunnuo.system.comm.controller.BaseController;
import com.yunnuo.system.comm.util.ResultData;
import com.yunnuo.system.comm.util.page.TableDataInfo;
import com.yunnuo.system.users.entity.PageParams;
import net.sf.json.JSON;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author 魏洪福（15064000912@163.com）
 * @create 2018-09-26-9:30
 */
@Controller
@RequestMapping("monitor/jobLog")
public class JobLogController extends BaseController {

    private String prefix = "monitor/jobLog";
    @Autowired
    private IJobLogService jobLogService;

    @GetMapping()
    public String job()
    {
        return prefix + "/jobLog";
    }

    /**
     * 分页查询
     * @param pageParams
     * @return
     */
    @RequiresPermissions("monitor:jobLog:list")
    @GetMapping("/list")
    @ResponseBody
    public TableDataInfo list(PageParams pageParams)
    {
        return jobLogService.selecJobLogByPageParams(pageParams,startPage(pageParams));
    }
    @RequiresPermissions("monitor:jobLog:remove")
    @RequestMapping("/remove/{id}")
    @ResponseBody
    public JSON remove(@PathVariable("id")String id)
    {
        ResultData data = new ResultData();
        try{

            MonJobLog jobLog=jobLogService.findVO(id);
            if (jobLog == null)
            {
                data.setStat(ResultData.STAT_FAILURE);
                data.setMessage("定时任务日志不存在！");
            }
            jobLog.setStatus("2");
            jobLogService.addVO(jobLog);
            data.setStat(ResultData.STAT_SUCCESS);
            data.setMessage("操作成功！");
        }catch (Exception e){
            data.setStat(ResultData.STAT_FAILURE);
            data.setMessage("删除失败！");
        }
        return data.toJson();
    }

}
